﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using jade.core;
using jade.core.behaviours;
using jade.lang.acl;

namespace CMS1 {
    public class Dealer : Agent {

        public const int OFFER_ACCEPTED = 3001;

        public const int NO_OFFER_ACCEPTED = 3002;

        protected DatabaseWrapper db;
        protected static int CONF_ID = 1;
        protected static string myConf = "conf_id='" + CONF_ID + "'";

        public override void setup() {
            db = new DatabaseWrapper();
            db.initConnection(DatabaseWrapper.connString);
        }
        /*************************************************
         * Receive Internal
         * **********************************************/
        class ReceiveInternalMsgs : CyclicBehaviour {
            MessageTemplate internalMsg;
            DatabaseWrapper db;
            public ReceiveInternalMsgs(DatabaseWrapper db) {
                this.db = db;
                internalMsg = MessageTemplate.MatchSender(new AID("Communicator", AID.ISLOCALNAME));
            }
            public override void action() {
                ACLMessage msg = myAgent.receive(internalMsg);
                if (msg != null) {
                    int purpose = Convert.ToInt32(msg.getContent().Substring(0, 4));
                    /*switch (purpose) {
                        case Communicator.CHOOSE_OFFER:
                            break;
                    }*/
                } else {
                    block();
                }
            }
        }
    }
}